//
//  InlandCollectionCell.m
//  FreeTrip
//
//  Created by 邓芮 on 15/11/24.
//  Copyright © 2015年 邓芮. All rights reserved.
//

#import "InlandCollectionCell.h"

@interface InlandCollectionCell ()
// 背景图片
@property (nonatomic, strong) UIImageView *icon;

@property (nonatomic, strong) UILabel *areaLabel;

@property (nonatomic, strong) UILabel *areaEnglishLabel;

@end

@implementation InlandCollectionCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.icon = [[UIImageView alloc]initWithFrame:self.bounds];
        [self.contentView addSubview:self.icon];
        
        UIView *view = [[UIView alloc]initWithFrame:self.icon.frame];
        view.backgroundColor = [UIColor blackColor];
        view.alpha = 0.2;
        [self.contentView addSubview:view];
    
        UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressAction:)];
        longPress.minimumPressDuration = 0.5;
        [view addGestureRecognizer:longPress];
        
        
        
        CGFloat y = (self.icon.frame.size.height - 60 * KScreenWidth / 414) / 2;
        CGFloat height = 30 * KScreenWidth / 414;
        CGFloat width = self.icon.frame.size.width;
        self.areaLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, y, width, height)];
        self.areaLabel.textAlignment = NSTextAlignmentCenter;
        self.areaLabel.textColor = [UIColor whiteColor];
        self.areaLabel.text = @"中国";
        self.areaLabel.font = [UIFont systemFontOfSize:KScreenWidth / 21];
        //self.areaLabel.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:self.areaLabel];
        
        self.areaEnglishLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, y + height, width, height)];
        self.areaEnglishLabel.textColor = [UIColor whiteColor];
        self.areaEnglishLabel.textAlignment = NSTextAlignmentCenter;
        self.areaEnglishLabel.text = @"ZHONGGUO";
        self.areaEnglishLabel.font = [UIFont systemFontOfSize:KScreenWidth / 21];
        //self.areaEnglishLabel.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:self.areaEnglishLabel];
        
    }
    return self;
}

- (void)longPressAction:(UILongPressGestureRecognizer *)longPress
{
    UIView *view = longPress.view;
    switch (longPress.state)
    {
        case UIGestureRecognizerStateBegan:
        {
            [UIView animateWithDuration:0.5 animations:^{
                view.alpha = 0;
                self.areaEnglishLabel.alpha = 0;
                self.areaLabel.alpha = 0;
            }];
            break;
        }
        case UIGestureRecognizerStateEnded:
        {
            [UIView animateWithDuration:0.5 animations:^{
                view.alpha = 0.4;
                self.areaEnglishLabel.alpha = 1;
                self.areaLabel.alpha = 1;
            }];
            break;
        }
        default:
            break;
    }
}

- (void)setModel:(abAndeInModel *)model
{
    _model = model;
    [self.icon sd_setImageWithURL:[NSURL URLWithString:model.exsitUrl] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    self.areaLabel.text = model.name_zh_cn;
    self.areaEnglishLabel.text = model.name_en;
}


@end
